package com.grupoconstruobras.sigo.general.data;

import com.grupoconstruobras.sigo.general.data.Municipio;
import com.grupoconstruobras.sigo.general.data.Pais;

import java.io.Serializable;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.validation.constraints.NotNull;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.Immutable;
import org.hibernate.validator.constraints.NotEmpty;

/**
 * The persistent class for the m_departamento database table.
 */
@Entity
@Immutable
@Table(name = "departamento", schema = "public")
@Cache(usage = CacheConcurrencyStrategy.READ_ONLY)
public class Departamento implements Serializable {

  private static final long serialVersionUID = 4682611238589206783L;

  @Id
  @NotNull
  @NotEmpty
  @Column(name = "iddepartamento")
  private Integer idDepartamento;

  @Transient
  private String activo;

  @Column(name = "departamento")
  private String nombre;

  // bi-directional many-to-one association to Pais
  @ManyToOne(fetch = FetchType.LAZY)
  @JoinColumn(name = "idpais")
  private Pais MPai;

  // bi-directional many-to-one association to Municipio
  @OneToMany(mappedBy = "MDepartamento", fetch = FetchType.LAZY)
  private List<Municipio> MMunicipios;

  public Departamento() {
  }

  public Integer getIdDepartamento() {
    return this.idDepartamento;
  }

  public void setIdDepartamento(Integer idDepartamento) {
    this.idDepartamento = idDepartamento;
  }

  @Deprecated
  public String getActivo() {
//    return this.activo;
	  return "1";
  }

  @Deprecated
  public void setActivo(String activo) {
//    this.activo = activo;
  }

  public String getNombre() {
    return this.nombre;
  }

  public void setNombre(String nombre) {
    this.nombre = nombre;
  }

  public Pais getMPai() {
    return this.MPai;
  }

  public void setMPai(Pais MPai) {
    this.MPai = MPai;
  }

  public List<Municipio> getMMunicipios() {
    return this.MMunicipios;
  }

  public void setMMunicipios(List<Municipio> MMunicipios) {
    this.MMunicipios = MMunicipios;
  }

  @Override
  public boolean equals(Object other) {
    if (this == other) {
      return true;
    }
    if (other == null || !(other instanceof Departamento))
      return false;

    if (getIdDepartamento() != null)
      return getIdDepartamento().equals(((Departamento) other).getIdDepartamento());
    return super.equals(other);
  }

  @Override
  public int hashCode() {
    if (getIdDepartamento() == null)
      return super.hashCode();
    else
      return getIdDepartamento().hashCode();
  }

}
